import AWS from 'aws-sdk'
export const useAws = ({
  Bucket = 'test',
  queueSize = 5, // 并发数
  partSize = 5 * 1024 * 1024, // 设置分块的大小
}) => {
  const token =
    'Bearer eyJraWQiOiI3OUN3cG04SUFvT1ZaNHgydTlNb3pleXIxUTlDMGFPeiIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiIxODIzMjA1OTgxMCIsImF1ZCI6Ijc5Q3dwbThJQW9PVlo0eDJ1OU1vemV5cjFROUMwYU96IiwibmJmIjoxNzE0MDM3Mzc5LCJpc3MiOiJodHRwOi8vMTcyLjE2LjAuODQ6NjgyNCIsImV4cCI6MTcxNDEyMzc3OSwiaWF0IjoxNzE0MDM3Mzc5LCJqdGkiOiJmZTIwMTYyMS1lMjE4LTQ2MmMtOTU0OS0yZTYxOTAzNGJjZDkifQ.ZdTGo2nVeuU-sg4QsU3saBEaQrL5Lfy0BgQs6hKuei-WhyrIuoSI-L3Y2tUVkTJkXhPrXd70_KyrFhgYToiszucW_POEgLFMWBMMOQ_8WL1CpezwFmW3449DcBcGx-6sOxtlH8hpDmbmiXN3Li4RTfQfwhPrYR-jdscK55gscTJeCLFPs9lsosJ4peU-Um753A41LycyqtgfCS8CP7wUEQ6HyU9xz7dmVLWk6HG0XoZJ6T0YMQVIrYIZHFujjio1TQxMF3FX17lFyfl6TF_b-5HZgFV6F0gsT6XOOIc6crOHslzwtiSmKrQMyNbOHpodsECC8J8OoP6nQ--k9lQCrw'
  const s3 = new AWS.S3({
    endpoint: 'http://localhost:5600/api/file/s3/',
    accessKeyId: 'KxwRVS0fAkM2JyggkKFhcYGRolJicoKS',
    secretAccessKey: '8tREADBAcFBAQECAxhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcY',
    region: 'us-east-1',
    s3ForcePathStyle: true,
    signatureVersion: 'v4',
    forcePathStyle: true,
  })
  function upload(file) {
    const params = {
      Bucket,
      Key: '2024/' + file.name,
      Body: file,
      Metadata: {
        'Irock-Authorization': token,
      },
    }
    return new Promise((resolve, reject) => {
      const uploadTask = s3.upload(params, { queueSize, partSize })
      uploadTask.send((err, data) => {
        console.log(err)
        console.log(data)
        if (err) {
          reject(err)
        } else {
          resolve(data)
        }
        // {Location: 'irock/2024/brain.zip', Bucket: 'irock', Key: '2024/brain.zip', ETag: 'f6e8b6a35bee179cc179e39c9777fd8d'}
      })
    })
  }
  return {
    upload,
  }
}
